/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef _Vector2d_h_
#define _Vector2d_h_

/**
* file   Vector2d.h
* date   Mer 6 jan 2010 17:04:08 CET
* brief  TODO
*/

#include <math.h>

class Vector2d {
public:
  Vector2d(double x, double y) {
    coord_[0] = x;
    coord_[1] = y;
  }
  double get_x () const {
    return coord_[0];
  }
  double get_y () const {
    return coord_[1];
  }
  double operator[] (const size_t n) {
    return coord_[n];
  }
  bool operator== (const Vector2d& other) {
    return ((get_x() == other.get_x()) && (get_y() == other.get_y()));
  }
  Vector2d& operator= (const Vector2d& other) {
    coord_[0] = other.coord_[0];
    coord_[1] = other.coord_[1];
    return *this;
  }
  Vector2d& operator+ (const Vector2d& other) {
    coord_[0] += other.coord_[0];
    coord_[1] += other.coord_[1];
  }
  void get_normalized (Vector2d& v) {
    double norm2 = coord_[0] * coord_[0] + coord_[1] * coord_[1];
    double norm = sqrt(norm2);
    v.coord_[0] = coord_[0] / norm;
    v.coord_[1] = coord_[1] / norm;
  }
  double get_arg () {
    if (coord_[0] > 0) {
      return atan(coord_[1] / coord_[0]);
    }
    else if (coord_[0] < 0) {
      return M_PI - atan(coord_[1] / -coord_[0]);
    }
    else {
      return (coord_[1] >= 0) ? (+M_PI) : (-M_PI);
    }
  }
private:
  double coord_[2];
};

#endif

